package com.aspose.cells;

import java.util.HashMap;

class zceh {
   private Workbook a;
   private WorksheetCollection b;
   private int c;
   private int d;
   private byte[] e;
   private zcda f;
   private zbxz g;
   private com.aspose.cells.a.f.zi h;

   zceh(zcda var1) {
      this.f = var1;
      this.a = var1.a;
      this.b = this.a.getWorksheets();
   }

   void a(zbxz var1, com.aspose.cells.a.f.zi var2) throws Exception {
      this.h = var2;
      this.g = var1;

      while(true) {
         this.c = this.g.a();
         switch(this.c) {
         case 39:
            this.j();
            break;
         case 132:
            this.g.a(1L);
            return;
         case 135:
            this.d();
            break;
         case 143:
            this.f();
            break;
         case 153:
            this.c();
            break;
         case 157:
            this.a();
            break;
         case 353:
            this.k();
            break;
         case 386:
            this.h();
            break;
         case 397:
            this.e();
            break;
         case 534:
            this.g();
            break;
         case 548:
            this.b();
            break;
         case 549:
            this.i();
            break;
         default:
            this.d = this.g.b();
            if (this.d != 0) {
               this.g.a((long)this.d);
            }
         }
      }
   }

   private void g() {
      this.e = this.f.a(this.g);
      WorksheetCollection var1 = this.a.getWorksheets();
      int var2 = com.aspose.cells.b.a.zc.e(this.e, 0);
      boolean var3 = (this.e[4] & 255 & 1) != 0;
      boolean var4 = (this.e[4] & 255 & 2) != 0;
      boolean var5 = (this.e[4] & 255 & 4) != 0;
      if (var3 || var4) {
         zbvh var6 = var1.N();
         var6.b = var3;
         var6.a = var4;
         var6.a(var2);
      }

   }

   private void h() throws Exception {
      this.e = this.f.a(this.g);
      zqc var1 = new zqc((zauk)null);
      int var2 = com.aspose.cells.b.a.zc.a(this.e, 0);
      var1.c = zase.y(var2);
      byte var3 = 4;
      int[] var4 = new int[]{var3};
      String var5 = zcch.a(this.e, var4);
      int var7 = var4[0];
      HashMap var6 = this.f.b.a();
      if (!var6.containsKey(var5)) {
         throw new CellsException(6, "pivotCache rid " + var5 + " not found in workbook rels file");
      } else {
         var1.e = var5;
         com.aspose.cells.b.a.a.ze.a(this.f.b.h, (Object)var1);
      }
   }

   private void i() {
      this.e = this.f.a(this.g);
      this.b.setOleSize(zcch.a(this.e, 0));
   }

   private void j() throws Exception {
      this.e = this.f.a(this.g);
      Name var1 = new Name(this.b);
      var1.a(com.aspose.cells.b.a.zc.a(this.e, 0));
      var1.a(this.e[4]);
      var1.setSheetIndex(com.aspose.cells.b.a.zc.a(this.e, 5) + 1);
      byte var2 = 9;
      int[] var3 = new int[]{var2};
      String var4 = zcch.a(this.e, var3);
      int var7 = var3[0];
      if (var1.n() == 0) {
         var1.f(var4);
      }

      if (var1.i() == null) {
         var1.g(var4);
      }

      byte[] var8 = new byte[this.e.length - var7];
      System.arraycopy(this.e, var7, var8, 0, var8.length);
      int var9 = com.aspose.cells.b.a.zc.a(this.e, var7);
      int var5 = com.aspose.cells.b.a.zc.a(this.e, var7 + 4 + var9);
      var1.a(new byte[var9 + 8 + var5]);
      System.arraycopy(this.e, var7, var1.b(), 0, var9 + 8 + var5);
      var7 += var9 + 8 + var5;
      int[] var6 = new int[]{var7};
      var1.setComment(zcch.a(this.e, var6));
      var7 = var6[0];
      if (var1.l() && !var1.k()) {
         var6 = new int[]{var7};
         var1.a(zcch.a(this.e, var6));
         var7 = var6[0];
         var6[0] = var7;
         var1.b(zcch.a(this.e, var6));
         var7 = var6[0];
         var6[0] = var7;
         var1.c(zcch.a(this.e, var6));
         var7 = var6[0];
         var6[0] = var7;
         var1.d(zcch.a(this.e, var6));
         var7 = var6[0];
      }

      this.b.getNames().a(var1, false);
   }

   private void k() throws Exception {
      this.g.a(1L);
      zbqf var1 = new zbqf();
      this.a.getWorksheets().a(var1);
      zbqg var2 = null;
      boolean var3 = false;

      while(true) {
         this.c = this.g.a();
         switch(this.c) {
         case 354:
            this.g.a(1L);
            if (!var3) {
               var2 = new zbqg(1);
               var1.a(var2);
               this.b.d(var1.getCount() - 1);
            }

            return;
         case 355:
            this.e = this.f.a(this.g);
            String var4 = zcch.d(this.e, 0);
            zqe var5 = (zqe)this.f.b.b().get(var4);
            HashMap var6 = null;
            String var7 = com.aspose.cells.b.a.d.zk.b(var5.e);
            String var8 = "xl/externalLinks/_rels/" + var7 + ".rels";
            if (this.h.a(var8, false) != -1) {
               zcfw var9 = zasr.a(this.h, var8, true);
               var6 = zajh.b(var9);
               var9.c();
            }

            String var13 = "xl/" + var5.e;
            var2 = new zbqg(0);
            zcbu var10 = new zcbu(this.f, var2);
            var10.a(zcda.a(this.h, var13), var6);
            var1.a(var2);
            break;
         case 357:
            this.g.a(1L);
            var3 = true;
            var2 = new zbqg(1);
            var1.a(var2);
            this.b.d(var1.getCount() - 1);
            break;
         case 358:
            this.g.a(1L);
            var2 = new zbqg(5);
            var1.a(var2);
            break;
         case 361:
            this.e = this.f.a(this.g);
            String var11 = zcch.d(this.e, 0);
            zuk var12 = new zuk(var2);
            var12.a(var11);
            com.aspose.cells.b.a.a.ze.a(var2.b(), (Object)var12);
            break;
         case 362:
            this.l();
            break;
         case 667:
            this.g.a(1L);
            var2 = new zbqg(2);
            var1.a(var2);
            break;
         default:
            this.d = this.g.b();
            this.g.a((long)this.d);
         }
      }
   }

   private void l() throws Exception {
      this.b.q().clear();
      this.e = this.f.a(this.g);
      int var1 = com.aspose.cells.b.a.zc.a(this.e, 0);
      boolean[] var2 = new boolean[this.b.getCount()];

      int var3;
      for(var3 = 0; var3 < var1; ++var3) {
         int var4 = com.aspose.cells.b.a.zc.a(this.e, 4 + var3 * 12);
         int var5 = com.aspose.cells.b.a.zc.a(this.e, 8 + var3 * 12);
         int var6 = com.aspose.cells.b.a.zc.a(this.e, 12 + var3 * 12);
         this.b.q().b(var4, var5, var6);
         if (var4 == this.b.u() && var5 == var6 && var5 < this.b.getCount() && var5 > 0) {
            var2[var5] = true;
         }
      }

      for(var3 = 0; var3 < var2.length; ++var3) {
         if (!var2[var3]) {
            this.b.q().b(this.b.u(), var3, var3);
         }
      }

   }

   void a() {
      this.e = this.f.a(this.g);
      byte var1 = 0;
      short var2 = com.aspose.cells.b.a.zc.b(this.e, 24);
      WorkbookSettings var3 = this.a.getSettings();
      if ((var2 & 1) != 0) {
         var3.setReCalculateOnOpen(true);
      } else {
         var3.setReCalculateOnOpen(false);
         int var4 = com.aspose.cells.b.a.zc.a(this.e, var1);
         var3.f = var4;
      }

      int var5 = var1 + 4;
      switch(this.e[var5]) {
      case 0:
         var3.setCalcMode(2);
         break;
      case 1:
         var3.setCalcMode(0);
         break;
      case 2:
         var3.setCalcMode(1);
      }

      var5 += 4;
      if ((var2 & 4) != 0) {
         var3.setIteration(true);
         var3.setMaxIteration(com.aspose.cells.b.a.zc.a(this.e, var5));
         var3.setMaxChange(com.aspose.cells.b.a.zc.f(this.e, var5 + 4));
      } else {
         var3.setIteration(false);
      }

      var5 += 12;
      if ((var2 & 2) == 0) {
         var3.a(true);
      }

      if ((var2 & 8) == 0) {
         var3.setPrecisionAsDisplayed(true);
      }

      if ((var2 & 32) != 0) {
         var3.setRecalculateBeforeSave(true);
      }

   }

   void b() {
      this.e = this.f.a(this.g);
      WorkbookSettings var1 = this.a.getSettings();
      var1.setRecommendReadOnly(this.e[0] == 0);
      var1.a(com.aspose.cells.b.a.zc.e(this.e, 2));
   }

   void c() throws Exception {
      zpd var1 = this.a.b.i;
      this.e = this.f.a(this.g);
      if ((this.e[0] & 255 & 1) != 0) {
         this.a.getSettings().setDate1904(true);
      }

      this.a.getSettings().setRemovePersonalInformation((this.e[0] & 255 & 8) != 0);
      byte var2 = 0;
      switch(this.e[1] & 255 & 3) {
      case 0:
         var2 = 0;
         break;
      case 1:
         var2 = 1;
         break;
      case 2:
         var2 = 2;
      }

      this.a.getSettings().setUpdateLinksType(var2);
      this.a.getSettings().setHidePivotFieldList((this.e[1] & 255 & 4) != 0);
      var1.e = (this.e[1] & 255 & 8) >> 3 != 0;
      var1.d = com.aspose.cells.b.a.zo.a(com.aspose.cells.b.a.zc.a(this.e, 4));
      byte var3 = 8;
      int[] var4 = new int[]{var3};
      String var5 = zcch.a(this.e, var4);
      int var6 = var4[0];
      if (var5.length() > 0) {
         this.a.getWorksheets().a(var5);
      }

   }

   void d() {
      this.g.a(1L);

      while(true) {
         this.c = this.g.a();
         switch(this.c) {
         case 136:
            this.g.a(1L);
            return;
         case 158:
            this.e = this.f.a(this.g);
            byte var1 = 0;
            this.b.n().getSettings().b(com.aspose.cells.b.a.zc.a(this.e, var1));
            int var2 = var1 + 4;
            this.b.n().getSettings().c(com.aspose.cells.b.a.zc.a(this.e, var2));
            var2 += 4;
            this.b.n().getSettings().d(com.aspose.cells.b.a.zc.a(this.e, var2));
            var2 += 4;
            this.b.n().getSettings().e(com.aspose.cells.b.a.zc.a(this.e, var2));
            var2 += 4;
            this.b.n().getSettings().setSheetTabBarWidth(com.aspose.cells.b.a.zc.a(this.e, var2));
            var2 += 4;
            this.b.l(com.aspose.cells.b.a.zc.a(this.e, var2));
            var2 += 4;
            this.b.b(com.aspose.cells.b.a.zc.a(this.e, var2));
            var2 += 4;
            this.b.n().getSettings().setHidden((this.e[var2] & 255 & 1) != 0);
            this.b.n().getSettings().setMinimized((this.e[var2] & 255 & 4) != 0);
            this.b.n().getSettings().setHScrollBarVisible((this.e[var2] & 255 & 8) != 0);
            this.b.n().getSettings().setVScrollBarVisible((this.e[var2] & 255 & 16) != 0);
            this.b.n().getSettings().setShowTabs((this.e[var2] & 255 & 32) != 0);
            break;
         default:
            throw new CellsException(6, "Invalid workbook setting in the xlsb workbook.");
         }
      }
   }

   void e() throws Exception {
      this.e = this.f.a(this.g);
      znd var1 = new znd();
      this.b.k().a(var1);
      byte var2 = 0;
      var1.c = com.aspose.cells.b.a.zc.a(this.e, var2);
      int var5 = var2 + 4;
      var1.e = com.aspose.cells.b.a.zc.a(this.e, var5) - var1.c;
      var5 += 4;
      var1.d = com.aspose.cells.b.a.zc.a(this.e, var5);
      var5 += 4;
      var1.f = com.aspose.cells.b.a.zc.a(this.e, var5) - var1.d;
      var5 += 4;
      var1.a = com.aspose.cells.b.a.zc.a(this.e, var5);
      var5 += 4;
      var1.h = com.aspose.cells.b.a.zc.a(this.e, var5);
      var5 += 4;
      byte[] var3 = new byte[16];
      System.arraycopy(this.e, var5, var3, 0, 16);
      var1.b = new com.aspose.cells.b.a.zh(var3);
      var5 += 16;
      var1.i = com.aspose.cells.b.a.zc.b(this.e, var5);
      var5 += 2;
      int var4 = com.aspose.cells.b.a.zc.a(this.e, var5);
      var1.l((var4 & 1) != 0);
      var1.n((var4 & 2) != 0);
      var1.c((var4 & 4) != 0);
      var1.d((var4 & 8) != 0);
      var1.m((var4 & 16) != 0);
      var1.a((var4 & 32) != 0);
      var1.b((var4 & 64) != 0);
      switch(var4 & 384) {
      case 0:
         var1.a(2);
         break;
      case 128:
         var1.a(1);
         break;
      case 256:
         var1.a(0);
      }

      switch(var4 & 1536) {
      case 0:
         var1.b(0);
         break;
      case 512:
         var1.b(2);
         break;
      case 1024:
         var1.b(1);
      }

      var1.e((var4 & 2048) != 0);
      var1.f((var4 & 4096) != 0);
      var1.h((var4 & 8192) != 0);
      var1.i((var4 & 16384) != 0);
      var1.j((var4 & '耀') != 0);
      var1.k((var4 & 65536) != 0);
      var5 += 4;
      var1.j = zcch.d(this.e, var5);
   }

   void f() throws Exception {
      this.g.a(1L);
      zhu.c();
      this.a.getWorksheets().clear();
      int var1 = 0;
      int var2 = 1;

      while(true) {
         this.c = this.g.a();
         switch(this.c) {
         case 144:
            this.b.b = var2;
            this.g.a(1L);
            return;
         case 156:
            this.e = this.f.a(this.g);
            byte var3 = 4;
            int var4 = com.aspose.cells.b.a.zc.a(this.e, var3);
            int var11 = var3 + 4;
            int[] var5 = new int[]{var11};
            String var6 = zcch.a(this.e, var5);
            var11 = var5[0];
            var5[0] = var11;
            String var7 = zcch.a(this.e, var5);
            var11 = var5[0];
            Worksheet var8 = this.a.getWorksheets().add(var7);
            var8.g = new zpr(var8);
            var8.c(var4);
            if (var4 > var2) {
               var2 = var4;
            }

            if (this.e[0] == 1) {
               var8.a(false, false);
            } else if (this.e[0] == 2) {
               var8.a(false, true);
            }

            Object var9 = null;
            zpa var10 = new zpa((zoz)var9, var8);
            var10.d = var8;
            var10.a = var1;
            var10.b = com.aspose.cells.b.a.zo.a(var4);
            var10.c = var6;
            com.aspose.cells.b.a.a.ze.a(this.f.b.c, (Object)var10);
            this.f.b.b.put(var1, var10);
            ++var1;
            break;
         default:
            throw new CellsException(6, "Invalid workbook setting in the xlsb workbook.");
         }
      }
   }
}
